/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package dao;

import java.util.List;
import org.hibernate.Query;
import org.hibernate.Session;
import pojo.Loaitaikhoan;
import util.HibernateUtil;

/**
 *
 * @author WMThiet
 */
public class LoaiTaiKhoanDAO {
    public static Loaitaikhoan LayLoaiTaiKhoan(int type){
        Session session = HibernateUtil.getSessionFactory().openSession();
        Loaitaikhoan loaiTK = null;
        try{            
            session.beginTransaction();            
            loaiTK = (Loaitaikhoan)session.get(Loaitaikhoan.class,type);        
        }
        catch(Exception ex){
            loaiTK = null;
        }finally{
            session.close();
        }
        
        return loaiTK;
    }
    
    public static List<Loaitaikhoan> LayLoaiTaiKhoan(){
        Session session = HibernateUtil.getSessionFactory().openSession();
        List<Loaitaikhoan> listLoai = null;
        try{            
            session.beginTransaction();            
            String hql = "from Loaitaikhoan";   
            
            Query query = session.createQuery(hql);
            listLoai = query.list();
            
        }
        catch(Exception ex){
            listLoai = null;
        }finally{
            session.close();
        }
        
        return listLoai;
    }
}
